/**
 * Created by liyl on 2017/7/31.
 */
import channelConfig from '../../../../api/config/channel/multi-channel'
import * as globalTypes from '../../../../mutation-types'
/**
  * 获取接入网站列表
  * @param data
  * @param data.platform 平台 "web" / app / sdk
  * @returns {*}
 */
export const queryAppWebchat = ({commit, state, rootState, dispatch}, data) => {
  return channelConfig.queryWebchat(data)
    .then(response => {
      if (response.success) {
        return response
      }
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 根据id查询接入网站
 * @param data._id 接入网站id
 * @returns {*}
 */
export const queryAppWebchatCfgById = ({commit, state, rootState, dispatch}, data) => {
  return channelConfig.queryWebchatCfgById(data)
    .then(response => {
      if (response.success) {
        return response
      }
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}

/**
 * 添加一个新的网站接入
 * @param data._id 接入网站id
 * @returns {*}
 */
export const addWebchatCfg = ({commit, state, rootState, dispatch}, data) => {
  return channelConfig.addWebchatCfg(data)
    .then(response => {
      if (response.success) {
        return response
      }
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 修改更新一个新的网站接入
 * @param data._id 接入网站id
 * @returns {*}
 */
export const updateAppWebchatCfg = ({commit, state, rootState, dispatch}, data) => {
  return channelConfig.updateWebchatCfg(data)
    .then(response => {
      if (response.success) {
        return response
      }
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}

/**
 * 删除一个网站接入
 * @param data._id 接入网站id
 * @returns {*}
 */
export const deleteAppCfg = ({commit, state, rootState, dispatch}, data) => {
  return channelConfig.deleteWebchatCfg(data)
    .then(response => {
      if (response.success) {
        return response
      }
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
